package project1;

import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author maciej
 */
public class Logic {
    
private Timer timer = new Timer();
    double rotateStep = 0.05;
    int moveStep = 80;
    int zoom = 50;
    private boolean update = true;
    Scene scene;
    Project1View view;
    
    public Logic(Project1View v){
         view = v;
         scene = new Scene();
         view.paintScene(scene.getProjection());
         timer.scheduleAtFixedRate(new CamTimer(), 500, 30);
    }
    //<editor-fold defaultstate="collapsed" desc="Rotation">
    public void aroundX(){
        scene.changeXPosition(4*moveStep);
        scene.changeYAngle(-2*rotateStep);
        update = true;
    }
    public void rotateXLeft() {
        scene.changeXAngle(-rotateStep);
        update = true;
    }

    public void rotateXRight() {
        scene.changeXAngle(rotateStep);
        update = true;
    }

    public void rotateYLeft() {
        scene.changeYAngle(-rotateStep);
        update = true;
    }

    public void rotateYRight() {
        scene.changeYAngle(rotateStep);
        update = true;
    }

    public void rotateZLeft() {
        scene.changeZAngle(-rotateStep);
        update = true;
    }

    public void rotateZRight() {
        scene.changeZAngle(rotateStep);
        update = true;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Move">

    public void moveRight() {
        scene.changeXPosition(moveStep);
        update = true;
    }

    public void moveLeft() {
        scene.changeXPosition(-moveStep);
        update = true;
    }

    public void moveDown() {
        scene.changeYPosition(-moveStep);
        update = true;
    }

    public void moveUp() {
        scene.changeYPosition(moveStep);
        update = true;
    }

    public void moveBackward() {
        scene.changeZPosition(moveStep);
        update = true;
    }

    public void moveForward() {
        scene.changeZPosition(-moveStep);
        update = true;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Zoom">
    public void zoomIn() {
        scene.zoom(zoom);
        update = true;
    }

    public void zoomOut() {
        scene.zoom(-zoom);
        update = true;
    }
    
    private class CamTimer extends TimerTask {
        @Override
        public void run() {
        if(update)
        { 
            view.paintScene(scene.getProjection());
            update = false;
        }
        }
        
    }
    //</editor-fold>
}
